/**
 * 功能描述
 */

define(function (require, exports, module) {
	var aw = require("ajaxwrapper");
	
	var QuestionnaireProfile_Events=require("../handler/QuestionnaireProfile_Events")
    var intentionregister_Props = require("../constant/returnvisit_Props");
    
    module.exports = {
        showDetail : function(widget,data,disabled,type){
        	widget.get("form").reset();
        	widget.get("Vform").reset();
        	widget.get("profile").reset();
			widget.show([".J-tab"]).hide([".J-grid"]);
			widget.get("subnav").hide(["checkInDate","status","search"]).show(["return","save"]);							
			if(disabled){
        		widget.get("subnav").hide(["save"]);
        	}
			widget.$(".J-other-answer").val("");
//			widget.get("form").setValue("type",type);
//			IntentionRegister_Events.changeBirthday(widget,data.personalInfo.birthday);
			/**
			 * 人员信息赋值
			 * 这垃圾代码……
			 */
			widget.get("form").setValue("pkTravelContract",data.pkTravelContract);
			widget.get("form").setValue("pkPersonalInfo",data.member.personalInfo.pkPersonalInfo);
			widget.get("form").setValue("name",data.member.personalInfo.name);
			widget.get("form").setValue("sex",data.member.personalInfo.sex);
			widget.get("form").setValue("idNumber",data.member.personalInfo.idNumber);
			widget.get("form").setValue("birthday",data.member.personalInfo.birthday);
			widget.get("form").setValue("age",moment().diff(data.member.personalInfo.birthday,'years'));
			widget.get("form").setValue("mobilePhone",data.member.personalInfo.mobilePhone);
			var personalInfo = data.member.personalInfo;
			var address = personalInfo.areaAddress !=null ? personalInfo.areaAddress : "";
			widget.get("form").setValue("houseRegister",address);
			widget.get("form").setValue("address",data.member.personalInfo.address);
			widget.get("form").setValue("zipCode",data.member.personalInfo.zipCode);
			
			// 给签约信息赋值
			widget.get("Vform").setValue("pkTravelContract",data.pkTravelContract);
			widget.get("Vform").setValue("contactNo",data.contactNo);
			widget.get("Vform").setValue("product",data.productRule.product.name);
			widget.get("Vform").setValue("productType",data.productType.name);
			widget.get("Vform").setValue("number",data.number);
			widget.get("Vform").setValue("price",data.price);
			widget.get("Vform").setValue("memberCertificates",data.memberCertificates);
			widget.get("Vform").setValue("signUpDate",data.signUpDate);
			widget.get("Vform").setValue("startDate",data.startDate);
			widget.get("Vform").setValue("endDate",data.endDate);
			widget.get("Vform").setValue("operator",data.operator.name);
			widget.get("Vform").setValue("description",data.description);
			widget.get("form").setDisabled(true);
        	widget.get("Vform").setDisabled(true);
			aw.ajax({
    			url: "api/customervisitrecord/query",
    			data: {
    				"visit.id":data.pkTravelContract,
    				"visit.type":"Contract",
    				fetchProperties:"*,questionAnswerSheet.questionAnswers.optionCell.*,questionAnswerSheet.questionAnswers.optionCell.question.*" 
    			},
    			dataType:"json",
    			success: function(dats){
    				if(dats.length>0){
    					QuestionnaireProfile_Events.setQuestionaire(dats[0].questionAnswerSheet,widget);
    					if(disabled){
    						widget.get("profile").setDisabled(true);
    					}
    				}else{
    					if(disabled){
    						widget.get("profile").setDisabled(true);
    					}
    				}
    			}
    		});
			
		},
    };
});
